package com.fhz.a1909.viewmodel;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;

import com.fhz.a1909.R;

public class MainActivity2 extends AppCompatActivity {
    private Button add2;
    private TextView num2;
    MyViewModel myViewModel;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        add2 = (Button) findViewById(R.id.add2);
        num2 = (TextView) findViewById(R.id.num2);

         myViewModel = new ViewModelProvider(this).get(MyViewModel.class);

         myViewModel.getInt().observe(this, new Observer<Integer>() {
             @Override
             public void onChanged(Integer integer) {
                 num2.setText(String.valueOf(integer));
             }
         });
    }
}